class Solution {
public:
    string minWindow(string s, string t) {
        vector<int> hash1(128), hash2(128);
        int kind = 0, count = 0;
        for (auto& ch : t)
            if (hash2[ch]++ == 0) kind++;
        int len = INT_MAX, pos = -1;
        for (int left = 0, right = 0; right < s.size(); right++)
        {
            char in = s[right];
            if (++hash1[in] == hash2[in]) count++;
            while (count == kind)
            {
                if (right - left + 1 < len)
                {
                    len = right - left + 1;
                    pos = left;
                }
                char out = s[left++];
                if (hash1[out]-- == hash2[out]) count--;
            }
        }
        if (pos == -1) return "";
        return s.substr(pos, len);
    }
};